package com.zzj.controller;


import com.github.pagehelper.PageInfo;
import com.zzj.bean.TableEmployee;
import com.zzj.service.TableEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * InnoDB free: 8192 kB 前端控制器
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@RestController
@RequestMapping("/employee")
@CrossOrigin
@Api("employee")
public class TableEmployeeController {

    @Autowired
    private TableEmployeeService employeeService;


    @GetMapping("/getEmp")
    @ApiOperation("获取员工信息")
    public PageInfo<TableEmployee> getEmployees(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize
    ){
        return employeeService.getEmployees(pageNum,pageSize);
    }



    @PostMapping("/addEmp")
    @ApiOperation("添加员工")
    public boolean addEmp(@RequestBody TableEmployee employee){
        if (employee != null){
            System.out.println("employee = " + employee);
            return employeeService.addEmp(employee);
        }
        return false;
    }

    @DeleteMapping("/delEmp")
    @ApiOperation("删除员工")
    public boolean delEmp(String uid){
        System.out.println("uid = " + uid);
        return employeeService.delEmp(uid);
    }

    @PutMapping("/updateEmp")
    @ApiOperation("更改员工")
    public boolean updateEmp(@RequestBody TableEmployee employee){
        System.out.println("employee = " + employee);
        return employeeService.updateEmp(employee);
    }

    @GetMapping("/getEmpByLike/{key}/{value}")
    @ApiOperation("模糊查询")
    public PageInfo<TableEmployee> getEmpByLike(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize,
            @PathVariable("key") String key,
            @PathVariable("value") String value){
        System.out.println("key = " + key);
        System.out.println("value = " + value);
        return employeeService.getEmpByLike(pageNum,pageSize,key,value);
    }
}

